<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<!--<form method="post" enctype="multipart/form-data" action="main.php">-->
Choose Directory:
<input type="file"
       multiple
       directory
       webkitdirectory
       mozdirectory><br/>
<!--  <input class="button" type="submit" value="Upload" name="upload"/>-->
<button id="upload-btn">UPLOAD</button>
<!--</form>-->

<script>
  var files = [];
  $(document).ready(function () {
    $("input").change(function () {
      console.log("change!")
      files = this.files;
    });
  });

  $("#upload-btn").click(function () {
    console.log("upload-btn UPLOAD")
    var fd = new FormData();
    var fd_info = [];
    for (var i = 0; i < files.length; i++) {
      fd.append("file[]", files[i]);
      // fd.append("file_info[]", files[i].webkitRelativePath);
      fd_info[i] = files[i].webkitRelativePath;
      console.log("fd_info", i, fd_info[i])
      // console.log("upload files", files[i].webkitRelativePath)
    }
    fd.append("fd_info", fd_info);
    console.log("upload files fd", fd)
    $.ajax({
      url: "files.php",
      method: "POST",
      data: fd,
      contentType: false,
      processData: false,
      cache: false,
      success: function (data) {
        // console.log(data);
      }
    });
  });
</script>
<pre>
<?php

//var_dump($_POST);
//var_dump($_POST);

//if (isset($_POST['upload'])) {
//  if ($_POST['foldername'] != "") {
//    $foldername = $_POST['foldername'];
//    var_dump($foldername);
//    if (!is_dir($foldername))
////      mkdir($foldername);
//    foreach ($_FILES['files']['name'] as $i => $name) {
//      if (strlen($_FILES['files']['name'][$i]) > 1) {
//        var_dump($_FILES['files']['tmp_name'][$i]);
////        move_uploaded_file($_FILES['files']['tmp_name'][$i], $foldername . '/' . $name);
//      }
//    }
//    echo "Folder is uploaded successfully ..";
//  } else
//    echo "Folder uploaded Failed!!";
//}
?>
</pre>
